/**********************************************************************************************/
/* FBL_Value_Time.h 	                                                   					  */
/*                                                                       					  */
/* Copyright Paradigma, 1993-2006															  */
/* All Rights Reserved                                                   					  */
/**********************************************************************************************/

#ifndef _FBL_Value_Time_h
	#define _FBL_Value_Time_h
#pragma once

#include <VShared/FBL/publ/Interfaces/FBL_I_ValueTime.h>

// FBL:
#include <VShared/FBL/publ/Values/FBL_Value_Numeric.h>


#include <VShared/FBL/publ/Headers/FBL_pre_header.h>


/**********************************************************************************************/
FBL_Begin_Namespace


/**********************************************************************************************/
SMART_CLASS(Value_time);
SMART_CLASS(Value_time_null);


/**********************************************************************************************/
union TimeEncoded;
enum EDateFormat;


/**********************************************************************************************/
// FAST STR => TIME
//
FBL_SHARED_EXP void Convert_str_time_aa_fast( 
	const char*			inStr, 
	const DTFormat*		inDTFormat,
	TimeEncoded&		outTimeEnc );

FBL_SHARED_EXP void Convert_str_time_uu_fast( 
	const UChar*		inStr, 
	const UChar*		inStrEnd, 
	const DTFormat*		inDTFormat,
	TimeEncoded&		outTimeEnc );


/**********************************************************************************************/
// FAST TIME => STR
//
FBL_SHARED_EXP tslen Convert_time_str_aa_fast( 
	const TimeEncoded&	inTimeEnc, 
	const char			inSep, 
	char*				outString );

FBL_SHARED_EXP tslen Convert_time_str_uu_fast( 
	const TimeEncoded&	inTimeEnc, 
	const UChar			inSep, 
	UChar*				outString );


/**********************************************************************************************/
// CONVERT with CHECKS
//
FBL_SHARED_EXP void Convert_str_time_aa_aux( 
	const char*			inStr,
	const DTFormat* 	inDTFormat,
	TimeEncoded&		ioTime );

FBL_SHARED_EXP void Convert_str_time_uu_aux( 
	const UChar*		inStr,
	const UChar*		inStrEnd,
	const DTFormat* 	inDTFormat,
	TimeEncoded&		ioTime );


/**********************************************************************************************/
// VALUE STRING <=> VALUE TIME
//
FBL_SHARED_EXP void Convert_str_time( 
	const I_Value*	inValue, 
	I_Value*		outValue );

FBL_SHARED_EXP void Convert_time_str( 
	const I_Value*	inValue, 
	I_Value*		outValue );


#pragma mark === Value_time_imp ===


/**********************************************************************************************/
// This class implements I_ValueTime interface
// 
class FBL_SHARED_EXP_CLASS Value_time_imp : 
	public I_ValueTime, 
	public Value_Numeric< kTypeTime, vcTime, policyInPlace_ulong >
{
		IMPLEMENT_UNKNOWN(Value_time_imp)											
		BEGIN_INTERFACE_TABLE(Value_time_imp)										
			IMPLEMENT_INTERFACE(I_Value)										
			IMPLEMENT_INTERFACE(I_ValueTime)										
			IMPLEMENT_INTERFACE(I_Serializable)										
		END_INTERFACE_TABLE()

	public://///////////////////////////////////////////////////////////////////////////////////

							Value_time_imp( const DTFormat* inDTFormat = NULL );
							Value_time_imp( 
								const Value_time_imp&	inOther,
								const DTFormat*			inDTFormat = NULL );

virtual						~Value_time_imp( void );

	// ---------------------
	// DateTimeFormat:

		// <DateTimeFormat> [r/w]
virtual	void				put_DTFormat( const DTFormat* inDTFormat ) throw();
virtual	const DTFormat*		get_DTFormat( void ) const throw();

	// ---------------------
	// Time properties
	
		// <Hour> [r/w]
virtual	ushort				get_Hours( void ) const;
virtual	void				put_Hours( ushort inHours );

		// <Minutes> [r/w]
virtual	ushort				get_Minutes( void ) const;
virtual	void				put_Minutes( ushort inMinutes );

		// <Seconds> [r/w]
virtual	ushort				get_Seconds( void ) const;
virtual	void				put_Seconds( ushort inSeconds );

		// <Millisecond> [r/w]
virtual	ushort				get_Milliseconds( void ) const;
virtual	void				put_Milliseconds( ushort inMilliseconds );

		// <Time> [r/w]
virtual	void				get_Time( 
								ushort& outHours, 
								ushort& outMinutes, 
								ushort& outSeconds,
								ushort& outMilliseconds ) const;

virtual	void				put_Time( 
								ushort 	inHours, 
								ushort 	inMinutes,
								ushort 	inSeconds, 
								ushort	inMilliseconds );


	public://///////////////////////////////////////////////////////////////////////////////////

// I_Value API:

		using Value_Numeric< kTypeTime, vcTime, policyInPlace_ulong >::Assign;

	// ---------------------
	//  Value access:
	
virtual String				get_String( tslen inLimit = -1 ) const;
virtual void				put_String( const String& inStr );

virtual UChar*				get_String( 
								UChar*			outString, 
								tslen 			inBufferChars = -1 ) const;

virtual void				put_String( 
								const UChar* 	inStart,  
								const UChar* 	inEnd = NULL );

virtual char*				get_String( 
								char*			outString, 
								tslen 			inBufferChars = -1 ) const;

virtual void				put_String( 
								const char* 	inStart,  
								const char* 	inEnd = NULL );

virtual ulong				get_MaxChars( void ) const throw() ;


	// ---------------------
	// Numeric properties:


virtual void				put_Boolean( bool inValue )		{ argused1( inValue ); }
virtual bool				get_Boolean( void ) const		{ return ( bool )( 0 ); }

virtual void				put_Byte( uchar inValue )		{ argused1( inValue ); }
virtual uchar				get_Byte( void ) const			{ return ( uchar )( 0 ); }

virtual void				put_Short( short inValue )		{ argused1( inValue ); }
virtual short				get_Short( void ) const			{ return ( short )( 0 ); }

virtual void				put_UShort( ushort inValue )	{ argused1( inValue ); }
virtual ushort				get_UShort( void ) const		{ return ( ushort )( 0 ); }

virtual void				put_Medium( long inValue )		{ argused1( inValue ); }
virtual long				get_Medium( void ) const		{ return ( long )( 0 ); }

virtual void				put_LLong( llong inValue )		{ argused1( inValue ); }
virtual llong				get_LLong( void ) const			{ return mValue; }

virtual void				put_ULLong( ullong inValue )	{ argused1( inValue ); }
virtual ullong				get_ULLong( void ) const		{ return ( ullong )( 0 ); }

virtual void				put_Float( float inValue )		{ argused1( inValue ); }
virtual float				get_Float( void ) const			{ return ( float )( 0 ); }

virtual void				put_Double( double inValue )	{ argused1( inValue ); }
virtual double				get_Double( void ) const		{ return ( double )( 0 ); }


	public://///////////////////////////////////////////////////////////////////////////////////

//#if FBL_TEST_CODE

virtual void				Init( void ) throw();
virtual void 				Increment( void ) throw(); 

//#endif // FBL_TEST_CODE


	protected://////////////////////////////////////////////////////////////////////////////////

		const DTFormat*		mDTFormat;			/// Date and time format.
		bool				mDTFormatOwner;
};


#pragma mark === Value_time ===


/**********************************************************************************************/
// Implements Value time.
// 
class FBL_SHARED_EXP_CLASS Value_time : public Value_time_imp
{

public://///////////////////////////////////////////////////////////////////////////////////

							Value_time( const DTFormat* inDTFormat = NULL );
							Value_time( 
								const Value_time&	inOther,
								const DTFormat*		inDTFormat = NULL );

							Value_time( 
								ushort 	inHours, 
								ushort 	inMinutes,
								ushort 	inSeconds, 
								ushort	inMilliseconds,
								const DTFormat*		inDTFormat = NULL );

virtual						~Value_time( void );


virtual	I_Value_Ptr			Clone( bool inCopyData = true ) const throw();

};


#pragma mark === Value_time_null ===


/**********************************************************************************************/
/** Implements Value time with nullable.
*/ 
class FBL_SHARED_EXP_CLASS Value_time_null : 
	public Value_time,
	protected policyNullable<policyInPlace_ulong>
{

	public:///////////////////////////////////////////////////////////////////////////////////

		typedef policyNullable<policyInPlace_ulong>				PN;


	public:///////////////////////////////////////////////////////////////////////////////////

							Value_time_null( 
								const DTFormat* 		inDTFormat = NULL );
								
							Value_time_null( 
								const Value_time_null&	inOther,
								const DTFormat*			inDTFormat = NULL );

							Value_time_null( 
								ushort 				inHours, 
								ushort 				inMinutes,
								ushort 				inSeconds, 
								ushort				inMilliseconds,
								const DTFormat*		inDTFormat = NULL );

virtual						~Value_time_null( void );


virtual	I_Value_Ptr			Clone( bool inCopyData = true ) const throw();

virtual bool				get_IsNullable( void ) const throw() { return true; }
virtual bool 				get_IsNull( void ) const throw();
virtual void 				put_IsNull( bool inValue ) throw();


	// ---------------------
	// Value compare methods:

virtual	int					Compare( 
								const I_Value& 	inOther,
								COMPARE_TYPE 	inCompareType = kNatureCompare ) const throw();
														
virtual String				get_String( 
								tslen 	inLimit = -1 ) const;

virtual UChar*				get_String( 
								UChar* 	outString, 
								tslen 	inBufferChars = -1 ) const;

virtual char*				get_String( 
								char* 	outString, 
								tslen 	inBufferChars = -1 ) const;
};


/**********************************************************************************************/
FBL_End_Namespace

#include <VShared/FBL/publ/Headers/FBL_post_header.h>

#endif // _FBL_Value_Time_h
